package com.itheima.web;

import com.itheima.service.IUserService;
import com.itheima.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/delUserServlet")
public class DelUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //查找被选中的id
        String id = request.getParameter("id");
        //调用service层的方法
        //创建对象
        IUserService service = new UserServiceImpl();
        int index = service.deleteUser(id);
        if (index>0) {
            response.sendRedirect(request.getContextPath()+"/findUserByPageServlet");
        }


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
